﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using TicketMGR.Hibernate.BusinessObjects;
namespace TicketMGR.Hibernate
{
    public class DAO
    {
        public static ISession OpenSession()
        {
            if (factory == null)
            {
                Configuration c = new Configuration();
                c.AddAssembly(Assembly.GetCallingAssembly());
                factory = c.BuildSessionFactory();
            }
            return factory.OpenSession();
        }
        static ISessionFactory factory;
        public static void CreateChannelAndSaveToDatabase(ObjectBase obj)
        {
            
            using (ISession session = OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(obj);
                    transaction.Commit();
                }
                
            }
        }
    }
}
